﻿using System;
using System.Diagnostics;
using System.Collections.Generic;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKCodeBase.WinForm;
using YJKStatisticTable.FastStatisticTable.Utility;
using YJKView;

using YArchitech.Revit;


namespace YJKStatisticTable.DoorAndWindowTable
{
	[Transaction(TransactionMode.Manual)]
	internal class CmdDoorWndStatisticTable : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{

            try
            {
                //GridToolExportImportExcel gridToolExportImportExcel = new GridToolExportImportExcel(false);
                FlexCell.Grid grid = new FlexCell.Grid();


                List<ViewPlan> list = new List<ViewPlan>();
                FilteredElementCollector filteredElementCollector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document).OfClass(typeof(ViewPlan));
                foreach (Element element in filteredElementCollector)
                {
                    ViewPlan viewPlan = element as ViewPlan;

                    if (viewPlan != null && viewPlan.ViewType == (ViewType)1 && viewPlan.GenLevel != null)
                    {
                        ElementId elementId = viewPlan.GetUnderLayParameter().AsElementId();
                    }
                }
            }
            catch (Exception ex)
            {
                string aaa = ex.Message;

                int kkk = 0;
            }










			CmdViewType types = CmdViewType.FloorPlan;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			WindowHandle windowHandle = null;
			if (windowHandle == null)
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				windowHandle = new WindowHandle(mainWindowHandle);
			}


            if (FastMaterialDlgApp.m_MyForm == null || FastMaterialDlgApp.m_MyForm.IsDisposed)
            {
                FastMaterialRequestHandler fastMaterialRequestHandler = new FastMaterialRequestHandler();
                ExternalEvent exEvent = ExternalEvent.Create(fastMaterialRequestHandler);
                FastMaterialDlgApp.m_MyForm = new YJKStatisticTable.FastStatisticTable.CommonForms.DlgFastMaterialStatistic(commandData, windowHandle, fastMaterialRequestHandler, exEvent, true);
            }


            FastMaterialDlgApp.m_MyForm.Show(windowHandle);


			//FastMaterialDlgApp.thisApp.ShowForm(commandData, windowHandle, true);
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
